package com.newjiabo.ski.service.impl;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import com.newjiabo.common.utils.DateUtils;
import com.newjiabo.common.utils.SecurityUtils;
import com.newjiabo.common.utils.SnowFlake;
import com.newjiabo.common.utils.StringUtils;
import com.newjiabo.ski.domain.dto.AssessDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.newjiabo.ski.mapper.SkiAssessMapper;
import com.newjiabo.ski.domain.SkiAssess;
import com.newjiabo.ski.service.ISkiAssessService;

import javax.annotation.Resource;

/**
 * 评价Service业务层处理
 *
 * @author CaoMengHui
 * @date 2023-10-19
 */
@Service
public class SkiAssessServiceImpl implements ISkiAssessService {

    @Resource
    private SkiAssessMapper skiAssessMapper;

    /**
     * 查询评价
     *
     * @param id 评价主键
     * @return 评价
     */
    @Override
    public SkiAssess selectSkiAssessById(String id) {
        return skiAssessMapper.selectSkiAssessById(id);
    }

    /**
     * 查询评价列表
     *
     * @param skiAssess 评价
     * @return 评价
     */
    @Override
    public List<SkiAssess> selectSkiAssessList(SkiAssess skiAssess) {
        return skiAssessMapper.selectSkiAssessList(skiAssess);
    }

    /**
     * 新增评价
     *
     * @param skiAssess 评价
     * @return 结果
     */
    @Override
    public int insertSkiAssess(SkiAssess skiAssess) {
        if(StringUtils.isEmpty(skiAssess.getId())){
            skiAssess.setId(SnowFlake.getIdStr());
        }
        skiAssess.setCreateTime(DateUtils.getNowDate());
        return skiAssessMapper.insertSkiAssess(skiAssess);
    }

    /**
     * 修改评价
     *
     * @param skiAssess 评价
     * @return 结果
     */
    @Override
    public int updateSkiAssess(SkiAssess skiAssess) {
        skiAssess.setUpdateTime(DateUtils.getNowDate());
        return skiAssessMapper.updateSkiAssess(skiAssess);
    }

    /**
     * 批量删除评价
     *
     * @param ids 需要删除的评价主键
     * @return 结果
     */
    @Override
    public int deleteSkiAssessByIds(String[] ids) {
        return skiAssessMapper.deleteSkiAssessByIds(ids);
    }

    /**
     * 删除评价信息
     *
     * @param id 评价主键
     * @return 结果
     */
    @Override
    public int deleteSkiAssessById(String id) {
        return skiAssessMapper.deleteSkiAssessById(id);
    }

    @Override
    public int comment(AssessDto assessDto) {
        AssessDto.AssessTypeDto assessTypeDto = assessDto.getAssessTypeDto();
        SkiAssess skiAssess = BeanUtil.copyProperties(assessDto, SkiAssess.class);
        skiAssess.setAssessCategoryJson(assessTypeDto.toString());
        if (StringUtils.isEmpty(skiAssess.getMemberId())) {
            skiAssess.setMemberId(SecurityUtils.getMemberId());
        }
        return this.insertSkiAssess(skiAssess);
    }
}
